package com.squirrel.serialportcore.machine.creator;

import com.squirrel.serialportcore.entity.mapper.PortQueueMapper;

/**
 * 名称规则创造者
 * 默认创造名称规则
 *
 * @author Squbi
 * @date 2021/3/21 18:17
 */
public class NameRuleCreator {

    private String appName;

    public NameRuleCreator(String appName) {
        this.appName = appName;
    }

    public PortQueueMapper creatName(String portName) {
        String outQ = creatQueueOutputName(portName);
        String outE = creatExchangeOutputName(portName);
        return new PortQueueMapper(
                creatQueueInputName(portName),
                outQ, outE,
                creatRoutingName(outE, outQ));
    }

    public String creatQueueInputName(String portName) {
        return "Q.TO." + appName + "." + portName;
    }

    public String creatQueueOutputName(String portName) {
        return "Q.FROM." + appName + "." + portName;
    }

    public String creatExchangeOutputName(String portName) {
        return "E.FROM." + appName + "." + portName;
    }

    public String creatRoutingName(String exchangeName, String queueName) {
        return exchangeName + ":" + queueName;
    }
}
